package com.lxhdj.management.security;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lxhdj.common.model.SystemUserModel;
import com.lxhdj.common.service.SystemUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class UserDetailsServiceImpl implements UserDetailsService {

    private final SystemUserService systemUserService;
    @Override
    public UserDetails loadUserByUsername(String username) {
        // 查询用户
        LambdaQueryWrapper<SystemUserModel> systemUserModelLambdaQueryWrapper = new LambdaQueryWrapper<>();
        systemUserModelLambdaQueryWrapper.eq(SystemUserModel::getUsername, username);
        SystemUserModel user = systemUserService.getOne(systemUserModelLambdaQueryWrapper);
        // 用户信息赋值给userDetails对象
        UserDetail userDetail = new UserDetail();
        userDetail.setUserModel(user);
        return userDetail;
    }
}
